package work.yixin.redis.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import work.yixin.redis.config.RedisRepository;
import work.yixin.redis.config.RedisRepositoryAspect;
import work.yixin.redis.service.RedisService;
/**
 * Redis测试
 * @author yunshang
 *
 */
@RedisRepository(value = 0)
@RestController
public class IndexRedisController {
	@Autowired
	private RedisService redisService;
	
	@RedisRepository(value = 0)
	@GetMapping("/")
	public Map<String, Object> index() {
		Map<String, Object> map = redisService.getMap0();
		map.put("Controller", RedisRepositoryAspect.LocalRedisJedis.get().keys("*"));
		return map;
	}
	@RedisRepository(value = 1)//优先级比类上的高
	@GetMapping("/1")
	public Map<String, Object> index1() {
		Map<String, Object> map = redisService.getMap1();
		map.put("Controller", RedisRepositoryAspect.LocalRedisJedis.get().keys("*"));
		return map;
	}
	
	@GetMapping("/2")
	public Map<String, Object> index2() {
		Map<String, Object> map = redisService.getMap2();
		map.put("Controller", RedisRepositoryAspect.LocalRedisJedis.get().keys("*"));
		return map;
	}

	@GetMapping("/3")
	public Map<String, Object> index3() {
		Map<String, Object> map = redisService.getMap3();
		map.put("Controller", RedisRepositoryAspect.LocalRedisJedis.get().keys("*"));
		return map;
	}
	
	@RedisRepository(value = 0)
	@GetMapping("/add")
	public String add() {
		return RedisRepositoryAspect.LocalRedisJedis.get().set("add2", "add2");
	}
	@RedisRepository(value = 1)
	@GetMapping("/add1")
	public String add1() {
		return RedisRepositoryAspect.LocalRedisJedis.get().set("add2", "add2");
	}
	
	@GetMapping("/add2")
	public String add2() {
		return RedisRepositoryAspect.LocalRedisJedis.get().set("add2", "add2");
	}
}
